﻿using System;
using System.Collections.ObjectModel;
using System.Linq;

namespace QuailDashboard.View.Helpers
{
    /// <summary>
    /// Provides an observable collection class with ability to sort
    /// </summary>
    /// <typeparam name="T">The type of the class</typeparam>
    public class SortableObservableCollection<T> : ObservableCollection<T>
    {
        /// <summary>
        /// Sorts the collection
        /// </summary>
        /// <param name="comparer">Compare delegate</param>
        public void Sort(Comparison<T> comparer)
        {
            var list = Items.ToList();
            list.Sort(comparer);
            Clear();

            foreach (var item in list)
            {
                Add(item);
            }
        }
    }
}
